package com.example.demo.service;

import com.example.demo.mapper.RecorderMappper;
import com.example.demo.pojo.AttenRecorder;
import com.example.demo.pojo.Rewar_Punish;
import com.example.demo.pojo.TrainingRecorder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class RecorderService {

    @Autowired
    private RecorderMappper recorderMappper;

    public List<AttenRecorder> getAllAtt(){ return recorderMappper.getAllAtten();}
    public void addNemAtt(AttenRecorder attenRecorder){ recorderMappper.addAtten(attenRecorder);}
    public AttenRecorder getAttById(Integer id){ return recorderMappper.getAttenById(id);}
    public void updateAtt(AttenRecorder attenRecorder){ recorderMappper.updateAtten(attenRecorder);}
    public void deleteAtt(Integer id){ recorderMappper.deleteAttById(id);}

    public List<Rewar_Punish> getAllR_P(){ return recorderMappper.getAllR_P();}
    public void addNewR_P(Rewar_Punish rewar_punish){ recorderMappper.addRe(rewar_punish);}
    public Rewar_Punish getReById(Integer id){ return recorderMappper.getReById(id);}
    public void updateRe(Rewar_Punish rewar_punish){ recorderMappper.updateRe(rewar_punish);}
    public void deleteRe(Integer id){ recorderMappper.deleteReById(id);}

    public List<TrainingRecorder> getAllTra(){ return recorderMappper.getAllTrain();}
    public void addNewTra(TrainingRecorder trainingRecorder){ recorderMappper.addTra(trainingRecorder);}
    public TrainingRecorder getTraById(Integer id){ return recorderMappper.getTrainById(id);}
    public void updateTra(TrainingRecorder trainingRecorder){ recorderMappper.updateTrain(trainingRecorder);}
    public void deleteTra(Integer id){ recorderMappper.deleteTraById(id);}


    public List<TrainingRecorder> getByConditions(String conditionText,
                                                 String conditionType,
                                                 Date startTime,
                                                 Date endTime) {
        if("".equals(conditionText.trim())){
            conditionText = null;
        }
        switch (conditionType){
            case "ID":
                conditionType = "training.tr_id";
                break;
            case "名字":
                conditionType = "training.tr_name";
                break;
            case "员工ID":
                conditionType = "training.s_id";
                break;
            default:
                conditionType = null;
        }
        return recorderMappper.selectTrainingRecorderByConditions(conditionText,conditionType,startTime,endTime);
    }

    public List<Rewar_Punish> getRewardsByConditions(String conditionText, String conditionType) {
        if("".equals(conditionText.trim())){
            conditionText = null;
        }
        switch (conditionType){
            case "ID":
                conditionType = "training.tr_id";
                break;
            case "名字":
                conditionType = "training.tr_name";
                break;
            case "员工ID":
                conditionType = "training.s_id";
                break;
            default:
                conditionType = null;
        }
        return recorderMappper.getRewardsByConditions(conditionText,conditionType);
    }
}
